﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Backend;
using Data_Layer;
using System.Xml;

namespace TestSystem
{
    class Program
    {
        static void Main(string[] args)
        {
            WebService.SOAPServiceClient webservice = new WebService.SOAPServiceClient();
            DBUsersBooking db = new DBUsersBooking();

            UsersBooking[] usersBookingsbyUserLoggedin = webservice.getallUsersBookingsbyUsername("admin");
            List<UsersBooking> usersBookingsbyUserLoggedin2 = db.getallUsersBookingbyUsername("admin");

            Console.WriteLine("Line1 WCF: " + usersBookingsbyUserLoggedin.Length);
            Console.WriteLine("Line2 DB: " + usersBookingsbyUserLoggedin2.Count);

            int[] allbookingNumbers = new int[usersBookingsbyUserLoggedin.Length];
            Booking[] neededBookingsList = new Booking[allbookingNumbers.Length];
            for (int i = 0; i < usersBookingsbyUserLoggedin.Length; i++)
            {
                allbookingNumbers[i] = usersBookingsbyUserLoggedin[i].BookingNO;
            }


            for (int i = 0; i < allbookingNumbers.Length; i++)
            {
                neededBookingsList = webservice.getallBookingsbybookingNO(allbookingNumbers[i]);
            }

            List<Booking> neededBookingslst = neededBookingsList.ToList();

            foreach (Booking booking in neededBookingslst)
            {
                Console.WriteLine(booking.BookingNO);
            }


            /*
            WebService.SOAPServiceClient soap = new WebService.SOAPServiceClient();
            Booking[] bookingsList = soap.getallBookingsbybookingNO(3365);
            

            for (int i = 0; i < bookingsList.Length; i++)
            {
                Console.WriteLine("TEST: " + bookingsList[i].TimeBooked_hours);
            }

            




            /*
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<Booking>" +
                        "<BookingNO>9328</BookingNO>" +
                        "<PlateNO>CJ24ViC</PlateNO>" +
                        "<StartTime>29-10-2013 22:57:10</StartTime>" +
                        "<Status>active</Status>" +
                        "<TimeBooked_hours>5</TimeBooked_hours>" +
                        "</Booking>");

            XmlNode root = doc.FirstChild;
            Console.WriteLine("!!! : " +root.OuterXml);
            Console.WriteLine("!!! : " + root.ChildNodes.Count + " -- " + doc.FirstChild.OuterXml);

            Console.WriteLine("TEST : " +root.FirstChild.OuterXml);
            Console.WriteLine("TEst 2 : " + root.ChildNodes.Count);

            /*
            //Console.WriteLine("Display the title element...");
            //Console.WriteLine(root.FirstChild.OuterXml);
                    

            //DBUsers dbusers = new DBUsers();
            //Users user1 = new Users();
            //user1.UserName="Vicc";
            //user1.PassWord="VicPW";
            //user1.Balance=25;
            //dbusers.createUser(user1);
            //dbusers.updateUser(user1);
            //dbusers.deleteUser("Vicc");
            //dbusers.readUser("Vicc");
            //dbusers.getallUsers();

            
            //Data_Layer.Connection.GetInstance().GetConnection();
            Booking booking = new Booking();

            booking.BookingNO = 1033;
            booking.PlateNO = "CJ 65 VHP";
            booking.Status = "active";
            booking.TimeBooked_hours = 3;
            booking.StartTime = "2013-10-15 22:10:20.000";

            String Query = "use Internship update Booking set " + "plateNO=" + "'" + booking.PlateNO + "', " + "status_=" + "'" + booking.Status + "', " + "bookedTime=" + booking.TimeBooked_hours + ", " + "startTime=" + "'" + booking.StartTime + "'" + " where bookingNO = " + booking.BookingNO;
            System.Console.WriteLine(Query);

            DateTime startTime = DateTime.Now;
            string startTime_ = startTime.ToString("yyyy-MM-dd H:mm:ss");
            //System.Console.WriteLine("!!!! " + startTime_);

            //booking1.StartTime = startTime_;

            DBBooking dbbooking1 = new DBBooking();
            //dbbooking1.createBooking(booking1);
            //dbbooking1.deleteBooking(1011);
            //System.Console.WriteLine( dbbooking1.readBooking(1001).StartTime);
            

            //Booking bookingtest = new Booking();
            //bookingtest = dbbooking1.readBooking(1001);

            //System.Console.WriteLine("PlateNO: " + bookingtest.PlateNO + " Status: " + bookingtest.Status + " Hours Booked: " + bookingtest.TimeBooked_hours);
            */
        }
    }
}
